package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.CldInsurance;
import com.cleaningcloud.cld.domain.CldInsuranceStatics;
import com.cleaningcloud.cld.domain.dto.CldInsuranceDto;
import com.cleaningcloud.cld.domain.dto.CldInsuranceStaffDto;
import com.cleaningcloud.cld.domain.excelExport.InsuranceExcelExport;
import com.cleaningcloud.cld.domain.excelExport.InsuranceResignExcelExport;
import com.cleaningcloud.cld.domain.vo.CldInsuranceVo;
import com.cleaningcloud.cld.service.ICldInsuranceService;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 保险管理Controller
 *
 * @author cleaningcloud
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/insurance")
public class CldInsuranceController extends BaseController {
    @Autowired
    private ICldInsuranceService cldInsuranceService;


    /**
     * 查询保险管理列表
     */
    @RequiresPermissions("cld:insurance:list")
    @GetMapping("/list")
    public TableDataInfo list(CldInsurance cldInsurance) {
        startPage();
        List<CldInsuranceVo> list = cldInsuranceService.selectCldInsuranceList(cldInsurance);
        return getDataTable(list);
    }

    @RequiresPermissions("cld:insurance:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InsuranceExcelExport insuranceExcelExport) {
        if (insuranceExcelExport.getType().equals("1")) {
            List<InsuranceExcelExport> list = cldInsuranceService.excelExport();
            ExcelUtil<InsuranceExcelExport> util = new ExcelUtil<InsuranceExcelExport>(InsuranceExcelExport.class);
            util.exportExcel(response, list, "保险管理");
        } else {
            List<InsuranceResignExcelExport> list = cldInsuranceService.excelResignExport();
            ExcelUtil<InsuranceResignExcelExport> util = new ExcelUtil<InsuranceResignExcelExport>(InsuranceResignExcelExport.class);
            util.exportExcel(response, list, "保险管理");
        }

    }


    /**
     * 获取保险管理详细信息
     */
    @RequiresPermissions("cld:insurance:query")
    @GetMapping(value = "/{insuranceId}")
    public AjaxResult getInfo(@PathVariable("insuranceId") Long insuranceId) {
        return success(cldInsuranceService.selectCldInsuranceByInsuranceId(insuranceId));
    }

    /**
     * 新增保险管理
     */
    @RequiresPermissions("cld:insurance:add")
    @Log(title = "保险管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldInsurance cldInsurance) {
        return toAjax(cldInsuranceService.insertCldInsurance(cldInsurance));
    }

    /**
     * 修改保险管理
     */
    @RequiresPermissions("cld:insurance:edit")
    @Log(title = "保险管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldInsurance cldInsurance) {
        return toAjax(cldInsuranceService.updateCldInsurance(cldInsurance));
    }

    /**
     * 删除保险管理
     */
    @RequiresPermissions("cld:insurance:remove")
    @Log(title = "保险管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{insuranceIds}")
    public AjaxResult remove(@PathVariable Long[] insuranceIds) {
        return toAjax(cldInsuranceService.deleteCldInsuranceByInsuranceIds(insuranceIds));
    }


    /**
     * 关联人员替换操作
     */
    @RequiresPermissions("cld:insurance:related")
    @Log(title = "保险管理", businessType = BusinessType.UPDATE)
    @PostMapping("/relatedPersonnel")
    public AjaxResult relatedPersonnel(@RequestBody CldInsuranceStaffDto cldInsuranceStaffDto) {
        return toAjax(cldInsuranceService.relatedPersonnel(cldInsuranceStaffDto));
    }

    /**
     * 查询保险管理列表
     */
    @GetMapping("/getList")
    public AjaxResult getList(CldInsurance cldInsurance) {
        List<CldInsuranceVo> list = cldInsuranceService.selectCldInsuranceList(cldInsurance);
        return success(list);
    }


    /**
     * 查询保险已关联人员
     */
    @GetMapping("/selectInsuranceStaff")
    public AjaxResult selectInsuranceStaff(CldInsuranceDto cldInsuranceDto) {
        return success(cldInsuranceService.selectInsuranceStaff(cldInsuranceDto));
    }


    /**
     * 历史操作记录统计
     */
    @GetMapping("/selectCldInsuranceStaffStatisticsList")
    public AjaxResult selectCldInsuranceStaffStatisticsList(CldInsuranceStaffDto cldInsuranceStaffDto) {
        return success(cldInsuranceService.selectCldInsuranceStaffStatisticsList(cldInsuranceStaffDto));
    }

    /**
     * 历史操作记录明细
     */
    @GetMapping("/selectCldInsuranceStaffList")
    public AjaxResult selectCldInsuranceStaffList(CldInsuranceStaffDto cldInsuranceStaffDto) {
        return success(cldInsuranceService.selectCldInsuranceStaffList(cldInsuranceStaffDto));
    }

    /**
     * 保险统计
     */
    @RequiresPermissions("cld:insurance:statics")
    @GetMapping("/insuranceStatistics")
    public TableDataInfo insuranceStatistics(CldInsuranceStatics cldInsuranceStatics) {
        startPage();
        List<CldInsuranceStatics> list = cldInsuranceService.insuranceStatistics(cldInsuranceStatics);
        return getDataTable(list);
    }


    /**
     * 保险统计
     */
    @GetMapping("/selectCldInsuranceAnalyze")
    public AjaxResult selectCldInsuranceAnalyze() {
        return success(cldInsuranceService.selectCldInsuranceAnalyze());
    }
}
